<template>
  <el-dialog
    title="选择数据项"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-row>
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="init()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.key"
            placeholder="参数名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="init()">查询</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row>
      <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" border>
        <el-table-column
        type="selection"
        header-align="center"
        align="center"
        max-height="100px"
        width="50">
      </el-table-column>
        <el-table-column
          property="name"
          label="中文名称"
          width="150"
        ></el-table-column>
        <el-table-column
          property="enName"
          label="逻辑名称"
          width="200"
        ></el-table-column>
        <el-table-column
          property="typeName"
          label="类型"
          width="200"
        ></el-table-column>
        <el-table-column
          property="valueLength"
          label="长度"
          width="200"
        ></el-table-column>
        <el-table-column
          property="description"
          label="描述"
          width="200"
        ></el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      >
      </el-pagination>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      dataForm: {
        key: "",
      },
      dataList: [],
    };
  },
  methods: {
      //初始化添加字段信息
    init() {
      this.visible = true;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/dbconfig/tbdbmodelcolumncommonly/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.dataList = this.dataList.map(function(item){
            item.modelColumn = 0;
            return item;
          })
          // console.log(this.dataList);
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.init();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.init();
    },
    ///向父组件发送消息
    dataFormSubmit(){
        // console.log(this.dataListSelections);
        var data = this.dataListSelections
        this.$emit("getSourceColumn",data);
    },
  },
};
</script>

<style>
</style>